package com.hongyuan.sellfitness.ui.find.view_mode;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import com.hongyuan.mvvmhabitx.binding.command.BindingAction;
import com.hongyuan.mvvmhabitx.binding.command.BindingCommand;
import com.hongyuan.sellfitness.base.CustomViewModel;
import com.hongyuan.sellfitness.base.ItemViewModel;
import com.hongyuan.sellfitness.ui.find.beans.PostCommentBean;

public class CommentChildItemViewModel extends ItemViewModel<CustomViewModel> {

    public ObservableField<PostCommentBean.ListBean.ListSBean> entity = new ObservableField<>();

    private ItemViewModel fatherItemModel;

    public CommentChildItemViewModel(@NonNull CustomViewModel viewModel,ItemViewModel fatherItemModel, PostCommentBean.ListBean.ListSBean bean) {
        super(viewModel);
        this.fatherItemModel = fatherItemModel;
        entity.set(bean);
    }

    //评论
    public BindingCommand comment = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            viewModel.itemClick(fatherItemModel);

            if(viewModel instanceof PostDetailsViewModel){
                PostDetailsViewModel fViewModel = (PostDetailsViewModel)viewModel;
                CommentItemViewModel commentItemViewModel = (CommentItemViewModel)fatherItemModel;

                viewModel.setParams("circle_id",String.valueOf(entity.get().getCircle_id()))
                        .setParams("cr_id_father",String.valueOf(entity.get().getCr_id()))
                        .setParams("first_cr_id",String.valueOf(commentItemViewModel.entity.get().getCr_id()));
                fViewModel.uc.showEdit.call();
            }
        }
    });
}
